<%@ page language="java" import="com.brother.model.LatLngAddress,com.brother.geocode.*,
com.brother.database.*,java.net.*,com.brother.util.*" contentType="text/html; charset=utf-8"   pageEncoding="utf-8"%><%
String action = request.getParameter("action");
String lat = request.getParameter("lat");
String lng = request.getParameter("lng");
String address = request.getParameter("address");
String locale = (String)session.getAttribute("locale");
String trackerId = (String)request.getParameter("trackerId");
if(action.equalsIgnoreCase("getcache")){ // 获取数据已经存在的地址
	LatLngAddress addr = GeoCoder.getAddress(lat,lng, locale); 
//    System.out.println(lat+"  "+lng+" :");
	if(addr == null){
		if(NigeriaAddress.getInstance().isIntesect(Float.parseFloat(lat),Float.parseFloat(lng))){
			address = NigeriaAddress.getInstance().getAddressByDB(Float.parseFloat(lat),Float.parseFloat(lng));
			if(address == null)
				address = "Nigeria"; 
			out.print("1="+lat+"`"+lng+"`"+address);
			GeoCoder.saveAddress(lat,lng,address,"en", null,null);
		}else if(MalaysiaAddress.getInstance().isIntesect(Float.parseFloat(lat),Float.parseFloat(lng))){
			address = MalaysiaAddress.getInstance().getAddressByDB(Float.parseFloat(lat),Float.parseFloat(lng));
			if(address == null)
				address = "Nigeria"; 
			out.print("1="+lat+"`"+lng+"`"+address);
			GeoCoder.saveAddress(lat,lng,address,"en", null,null);
		}else{
			out.print("0=no data");
			System.out.println("no data");
		}
	}else{
		out.print("1="+addr.getLat()+"`"+addr.getLng()+"`"+addr.getAddress());
		GeoCoder.updateRealTimeData(addr.getLat()+"",addr.getLng()+"",addr.getAddress().replaceAll("'", "\\\\'"),locale); 
		//System.out.println("found  address:thread:"+Thread.currentThread().getName()+" lat:"+lat+"  lng:"+lng);
	}
//1=40.124457`-74.03131`R. Carlos Martins, 1332-1388 - Vitória - ES, 2909
}else if(action.equalsIgnoreCase("setaddress")){ // 存入数据库新的地址
	address = URLDecoder.decode(address,"UTF-8");
	 
	GeoCoder.saveAddress(lat,lng,address,locale, request.getParameter("reportId"),trackerId);
	System.out.println("set Address:"+lat+"   "+lng+"   "+address);
}else if(action.equalsIgnoreCase("streetnames")){
	//System.out.println("streetnames  address,lat:"+lat+"   lng:"+lng);
}else if(action.equalsIgnoreCase("setreport")){
	System.out.println("set report Address:"+lat+"   "+lng+"   "+address+" "+request.getParameter("reportId")+" trackerid="+trackerId);
	
	GeoCoder.setReportAddress(lat+"", lng+"", address ,locale, request.getParameter("reportId"), trackerId);  
}



%><%
com.brother.database.DataBase.closeThreadConnection();
%>